using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Miris.HumanMilkAnalyser.DataModel;

namespace Miris.HumanMilkAnalyser.Repository.EntityFramework.Mapping
{
    public class AnalysisResultDiagnosticMessageMap : EntityTypeConfiguration<AnalysisResultDiagnosticMessage>
    {
        public AnalysisResultDiagnosticMessageMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.SampleNumber)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.MessageContent)
                .IsRequired()
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("AnalysisResultDiagnosticMessage");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.SampleNumber).HasColumnName("SampleNumber");
            this.Property(t => t.MessageContent).HasColumnName("MessageContent");

            // Relationships
            this.HasRequired(t => t.AnalysisResult)
                .WithMany(t => t.AnalysisResultDiagnosticMessages)
                .HasForeignKey(d => d.SampleNumber);

        }
    }
}
